from core.item import Item
from core.action import Action
from core.support import get_game, set_cutscene
from rooms.bridge import Bridge

class Vines(Item):
    def __init__(self):
        Item.__init__(self, "vines")    # do basic initialization for every item
        
        # build list of actions
        self.add_action(FixBridge)
    
    def get_description(self):
        return "vines"

# define actions for this item

class FixBridge(Action):
    def __init__(self):
        Action.__init__(self, "use_vines")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Use vines"
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"
    
    # only works in basement. add cutscene
    def do_action(self,game,room,request):
        if room.get_id() == 'bridge':
            if room.fixed:
                set_cutscene("The bridge has already been fixed.")
            else:
                #room.fix_bridge()
                player = game.get_player()
                player.pop_item('vines')
                room.fixed = True
                set_cutscene("You use the vines to fix the bridge!")
        else:
            set_cutscene("Nothing to use the vines on here.")
        return
    
    def is_enabled(self):
        game = get_game()
        room = game.get_room('bridge', Bridge)
        
        if room.fixed:
            return False
        else:
            return True